349C - Mafia - CodeForces Solution


implementation *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define pob pop_back
#define pub push_back
#define lb lower_bound
#define ub upper_bound
#define low (i&(-i))
#define le (node<<1)
#define ri (node<<1|1)
#define mid ((l+r)>>1)
#define no void(cout<<"NO\n")
#define zer void(cout<<"0\n")
#define one void(cout<<"-1\n")
#define yes void(cout<<"YES\n")
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define mm(x,y) memset(x,y,sizeof(x))

using namespace std ;

const int L = 23 ;
const int B = 750 ;
const int T = 1e3+3 ;
const int N = 1e6+6 ;
const int M = 1e9+7 ;
const int D = 998244353 ;
const long long O = 4557430888798830399 ;

int n , a[N] , sum ;

bool check ( int x ) {
    return n * x - sum >= x ;
}

inline void solve () {
    cin >> n ;
    for ( int i = 1 ; i <= n ; i++ ) {
        cin >> a[i] ;
        sum += a[i] ;
    }
    int l = *max_element ( a + 1 , a + n + 1 ) - 1 , r = 1e12 ;
    while ( r - l > 1 ) {
        if ( check ( mid ) ) {
            r = mid ;
        }
        else {
            l = mid ;
        }
    }
    cout << r ;
}

signed main () {
    //freopen ( ".in" , "r" , stdin ) ;
    //freopen ( ".out" , "w" , stdout ) ;
    cin.tie(0) ;
    cout.tie(0) ;
    ios_base::sync_with_stdio(0) ;
    //cout << setprecision(14) << fixed ;
    int tc = 1 ;
    //cin >> tc ;
    while ( tc-- ) {
        solve() ;
    }
    return 0 ;
}

///  JJJJJJJ EEEEEEE  AAAAA  NN   NN 7777777
///     JJ   EE      AA   AA NNN  NN     77
///     JJ   EEEEEE  AAAAAAA NN N NN    77
///  JJ JJ   EE      AA   AA NN  NNN   77
///  JJJJJ   EEEEEEE AA   AA NN   NN  77


Comments

Submit
0 Comments
More Questions

1705C - Mark and His Unfinished Essay
1401C - Mere Array
1613B - Absent Remainder
1536B - Prinzessin der Verurteilung
1699B - Almost Ternary Matrix
1545A - AquaMoon and Strange Sort
538B - Quasi Binary
424A - Squats
1703A - YES or YES
494A - Treasure
48B - Land Lot
835A - Key races
1622C - Set or Decrease
1682A - Palindromic Indices
903C - Boxes Packing
887A - Div 64
755B - PolandBall and Game
808B - Average Sleep Time
1515E - Phoenix and Computers
1552B - Running for Gold
994A - Fingerprints
1221C - Perfect Team
1709C - Recover an RBS
378A - Playing with Dice
248B - Chilly Willy
1709B - Also Try Minecraft
1418A - Buying Torches
131C - The World is a Theatre
1696A - NIT orz
1178D - Prime Graph